<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      function Person(name, age) {
        this.name = name;
        this.age = age;
      }
      // 构造函数继承 ---> 只能继承属性，不能继承原型
      Person.prototype.say = function () {
        console.log(this.name, "hello");
      };

      function Student(name, age, grade) {
        Person.call(this, name, age); // 继承(call 改变this指向)
        this.grade = grade;
      }

      // ----------------------------------------------------------------

      // 原型函数继承
      Student.prototype = new Person(); // 挂在原型上
      // 在基础上增加方法
      Student.prototype.like = function () {
        console.log(this.name, this.grade);
      };
      // 在基础上覆盖方法
      Student.prototype.say = function () {
        console.log(this.name, this.grade);
        console.log(this.name, "您好");
      };

      // ----------------------------------------------------------------
      var obj = new Student("cxm", 100, 100);
      console.log(obj); //Student age:100 grade:100 name:'cxm'

      obj.say();
    </script>
  </body>
</html>
